<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
use lib\Curl;
use lib\Crypt3Des;
class Bank extends Base{
    // private $mchntcd='0002900F0096235';//测试商户号
    // private $key='5old71wihg2tqjug9kkpxnhx9hiujoqj';//测试密钥
    private $mchntcd='0005210F1990688';//富友商户号
    private $key='bye9xcz6pfclt9uecmg08p42luq55pus';//代收付密钥
    private $fkey='3v79xo6jb1c7tns4gaihaxs58st4orts';//代收付交易密钥
    //银行
    public function banks(){
        $list=Db::name('bank')->where(array('status'=>1))->order('id asc')->select();
        if($list){
            return json(['code' => 200, 'msg' => '查询成功' ,'data' =>$list]);
        }else{
            return json(['code' => 500, 'msg' => '查询失败', 'data' =>$list]);
        }
    }
    //签约获取短信
    //des加密
    public function bank_authsms(){
        if(!empty(input("param.token"))){
            $token=input("param.token");//WKIDO4rV9PzkkA
        }else{
            return json(['code' => 501, 'msg' => '令牌呢？']);exit();
        }
        if(!empty(input("param.bank_name"))){
            $data['bank_name']=input("param.bank_name");
        }else{
            return json(['code' => 502, 'msg' => '持卡人不能为空']);exit();
        }
        if(!empty(input("param.bank_idcard"))){
            $data['bank_idcard']=input("param.bank_idcard");
        }else{
            return json(['code' => 503, 'msg' => '身份证不能为空']);exit();
        }
        if(!empty(input("param.bank_cdid"))){
            $data['bank_cdid']=input("param.bank_cdid");
        }else{
            return json(['code' => 504, 'msg' => '银行未选择']);exit();
        }
        if(!empty(input("param.bank_number"))){
            $data['bank_number']=input("param.bank_number");
        }else{
            return json(['code' => 505, 'msg' => '银行卡号不能为空']);exit();
        }
        if(!empty(input("param.bank_phone"))){
            $data['bank_phone']=input("param.bank_phone");
        }else{
            return json(['code' => 506, 'msg' => '预留手机号不能为空']);exit();
        }
        $data['mchntssn']=date('YmdHis').mt_rand(1000,9999);
        $id=$this->do_mdecrypt($token);
        Db::name('users')->where(array('id'=>$id))->update(array('mchntssn'=>$data['mchntssn']));
        $fdata['version']="1.0";
        $fdata['mchntcd']=$this->mchntcd;
        $fdata['userid']=$id; 
        $fdata['tradedate']=date('Ymd');
        $fdata['mchntssn']=$data['mchntssn'];//流水号
        $fdata['account']=$data['bank_name'];
        $fdata['cardno']=$data['bank_number'];
        $fdata['idtype']="0";
        $fdata['idcard']=$data['bank_idcard'];
        $fdata['mobileno']=$data['bank_phone'];
        $sign=$fdata['version'].'|'.$fdata['mchntssn'].'|'.$fdata['mchntcd'].'|'.$fdata['userid'].'|'.$fdata['account'].'|'.$fdata['cardno'].'|'.$fdata['idtype'].'|'.$fdata['idcard'].'|'.$fdata['mobileno'].'|'.$this->fkey;
        $xml='<?xml version="1.0" encoding="UTF-8" standalone="no"?>'.
        '<REQUEST>'.
        '<VERSION>1.0</VERSION>'.
        '<MCHNTCD>'.$fdata['mchntcd'].'</MCHNTCD>'.
        '<USERID>'.$fdata['userid'].'</USERID>'.
        '<TRADEDATE>'.$fdata['tradedate'].'</TRADEDATE>'.
        '<MCHNTSSN>'.$fdata['mchntssn'].'</MCHNTSSN>'.
        '<ACCOUNT>'.$fdata['account'].'</ACCOUNT>'.
        '<CARDNO>'.$fdata['cardno'].'</CARDNO>'.
        '<IDTYPE>'.$fdata['idtype'].'</IDTYPE>'.
        '<IDCARD>'.$fdata['idcard'].'</IDCARD>'.
        '<MOBILENO>'.$fdata['mobileno'].'</MOBILENO>'.
        '<SIGN>'.md5($sign).'</SIGN>'.
        '</REQUEST>';
        $des=Crypt3Des::encrypt_base64($xml,$this->fkey);
        //$url='http://www-1.fuioupay.com:18670/mobile_pay/newpropay/bindMsg.pay';//测试地址
        $url='https://mpay.fuioupay.com/newpropay/bindMsg.pay';//生产地址
        $datas['MCHNTCD']=$this->mchntcd;
        $datas['APIFMS']=$des;
        $res=Curl::http_curl($url,$datas);
        $ddes=Crypt3Des::decrypt_base64($res,$this->fkey);
        $vres=simplexml_load_string($ddes);
        if ($vres->RESPONSECODE==0000) {
            return json(['code' => 200, 'msg' =>$vres->RESPONSEMSG,'mchntssn' =>$vres->MCHNTSSN]);exit();
        }else{
            return json(['code' => $vres->RESPONSECODE,'msg' =>$vres->RESPONSEMSG]);exit();
        }
        
    }
    //提交短信验证码，协议卡绑定
    public function bank_authvb(){
        if(!empty(input("param.token"))){
            $token=input("param.token");
        }else{
            return json(['code' => 501, 'msg' => '令牌呢？']);exit();
        }
        if(!empty(input("param.bank_name"))){
            $data['bank_name']=input("param.bank_name");
        }else{
            return json(['code' => 502, 'msg' => '持卡人不能为空']);exit();
        }
        if(!empty(input("param.bank_idcard"))){
            $data['bank_idcard']=input("param.bank_idcard");
        }else{
            return json(['code' => 503, 'msg' => '身份证不能为空']);exit();
        }
        if(!empty(input("param.bank_cdid"))){
            $data['bank_cdid']=input("param.bank_cdid");
        }else{
            return json(['code' => 504, 'msg' => '银行未选择']);exit();
        }
        if(!empty(input("param.bank_number"))){
            $data['bank_number']=input("param.bank_number");
        }else{
            return json(['code' => 505, 'msg' => '银行卡号不能为空']);exit();
        }
        if(!empty(input("param.bank_phone"))){
            $data['bank_phone']=input("param.bank_phone");
        }else{
            return json(['code' => 506, 'msg' => '预留手机号不能为空']);exit();
        }
        if(!empty(input("param.bank_msgcode"))){
            $bank_msgcode=input("param.bank_msgcode");
        }else{
            return json(['code' => 507, 'msg' => '验证码不能为空']);exit();
        }
        $id=$this->do_mdecrypt($token);
        $user=Db::name('users')->where('id',$id)->find();
        $fdata['version']="1.0";
        $fdata['mchntcd']=$this->mchntcd;
        $fdata['userid']=$id; 
        $fdata['tradedate']=date('Ymd'); 
        $fdata['mchntssn']=$user['mchntssn'];//流水号
        $fdata['account']=$data['bank_name'];
        $fdata['cardno']=$data['bank_number'];
        $fdata['idtype']="0";
        $fdata['idcard']=$data['bank_idcard'];
        $fdata['mobileno']=$data['bank_phone'];
        $fdata['msgcode']=$bank_msgcode;
        $sign=$fdata['version'].'|'.$fdata['mchntssn'].'|'.$fdata['mchntcd'].'|'.$fdata['userid'].'|'.$fdata['account'].'|'.$fdata['cardno'].'|'.$fdata['idtype'].'|'.$fdata['idcard'].'|'.$fdata['mobileno'].'|'.$fdata['msgcode'].'|'.$this->fkey;
        $xml='<?xml version="1.0" encoding="UTF-8" standalone="no"?>'.
        '<REQUEST>'.
        '<VERSION>1.0</VERSION>'.
        '<MCHNTCD>'.$fdata['mchntcd'].'</MCHNTCD>'.
        '<USERID>'.$fdata['userid'].'</USERID>'.
        '<TRADEDATE>'.$fdata['tradedate'].'</TRADEDATE>'.
        '<MCHNTSSN>'.$fdata['mchntssn'].'</MCHNTSSN>'.
        '<ACCOUNT>'.$fdata['account'].'</ACCOUNT>'.
        '<CARDNO>'.$fdata['cardno'].'</CARDNO>'.
        '<IDTYPE>0</IDTYPE>'.
        '<IDCARD>'.$fdata['idcard'].'</IDCARD>'.
        '<MOBILENO>'.$fdata['mobileno'].'</MOBILENO>'.
        '<MSGCODE>'.$fdata['msgcode'].'</MSGCODE>'.
        '<SIGN>'.md5($sign).'</SIGN>'.
        '</REQUEST>';
        $des=Crypt3Des::encrypt_base64($xml,$this->fkey);
        $url='http://www-1.fuioupay.com:18670/mobile_pay/newpropay/bindCommit.pay';
        // $url='https://mpay.fuioupay.com/newpropay/bindCommit.pay';
        $datas['MCHNTCD']=$this->mchntcd;
        $datas['APIFMS']=$des;
        $res=Curl::http_curl($url,$datas);
        $ddes=Crypt3Des::decrypt_base64($res,$this->fkey);
        $vres=simplexml_load_string($ddes);//返回里的协议号 PROTOCOLNO 有什么作用
        if ($vres->RESPONSECODE==0000) {
            $data['protocolno']=$vres->PROTOCOLNO;
            $dbres=Db::name('users')->where(array('id'=>$id))->update($data);
            if ($dbres) {
                return json(['code' => 200, 'msg' =>$vres->RESPONSEMSG]);exit();
            }else{
                return json(['code' => 500, 'msg' =>'入库失败']);exit();
            }
        }else{
            return json(['code' => $vres->RESPONSECODE, 'msg' =>$vres->RESPONSEMSG]);exit();
        }

    }
    //协议卡解绑
    public function bank_authunb(){
        if(!empty(input("param.token"))){
            $token=input("param.token");
        }else{
            return json(['code' => 501, 'msg' => '令牌呢？']);exit();
        }
        $id=$this->do_mdecrypt($token);
        $user=Db::name('users')->where('id',$id)->find();
        $exitorder=Db::name('orders')->where('user_id',$id)->where(['state'=>[17,19]])->find();
        if($exitorder){
            return json(['code' => 502, 'msg' => '存在未还款订单']);exit();
        }
        $fdata['version']="1.0";
        $fdata['mchntcd']=$this->mchntcd;
        $fdata['userid']=$id; 
        $fdata['protocolno']=$user['protocolno'];
        $sign=$fdata['version'].'|'.$fdata['mchntcd'].'|'.$fdata['userid'].'|'.$fdata['protocolno'].'|'.$this->fkey;
        $xml='<?xml version="1.0" encoding="UTF-8" standalone="no"?>'.
        '<REQUEST>'.
        '<VERSION>1.0</VERSION>'.
        '<MCHNTCD>'.$fdata['mchntcd'].'</MCHNTCD>'.
        '<USERID>'.$fdata['userid'].'</USERID>'.
        '<PROTOCOLNO>'.$fdata['protocolno'].'</PROTOCOLNO>'.
        '<SIGN>'.md5($sign).'</SIGN>'.
        '</REQUEST>';
        $des=Crypt3Des::encrypt_base64($xml,$this->fkey);
        $url='http://www-1.fuioupay.com:18670/mobile_pay/newpropay/unbind.pay';
        // $url='https://mpay.fuioupay.com/newpropay/unbind.pay';
        $datas['MCHNTCD']=$this->mchntcd;
        $datas['APIFMS']=$des;
        $res=Curl::http_curl($url,$datas);
        $ddes=Crypt3Des::decrypt_base64($res,$this->fkey);
        $vres=simplexml_load_string($ddes);//返回里的协议号 PROTOCOLNO 有什么作用
        if ($vres->RESPONSECODE==0000) {
            $dbres=Db::name('users')->where(array('id'=>$id))->update(['bank_number'=>null]);
            if ($dbres) {
                return json(['code' => 200, 'msg' =>$vres->RESPONSEMSG]);exit();
            }else{
                return json(['code' => 500, 'msg' =>'数据清空失败']);exit();
            }
        }else{
            return json(['code' => $vres->RESPONSECODE, 'msg' =>$vres->RESPONSEMSG]);exit();
        }

    }
    //协议卡解绑20
    public function bank_authunbtest(){
        // $id=20;
        // $user=Db::name('users')->where('id',$id)->find();
        $fdata['version']="1.0";
        $fdata['mchntcd']=$this->mchntcd;
        $fdata['userid']=20; 
        $fdata['protocolno']='YQ6D5I100045050001L7GR';
        $sign=$fdata['version'].'|'.$fdata['mchntcd'].'|'.$fdata['userid'].'|YQ6D5I100045050001L7GR|'.$this->fkey;
        $xml='<?xml version="1.0" encoding="UTF-8" standalone="no"?>'.
        '<REQUEST>'.
        '<VERSION>1.0</VERSION>'.
        '<MCHNTCD>'.$fdata['mchntcd'].'</MCHNTCD>'.
        '<USERID>'.$fdata['userid'].'</USERID>'.
        '<PROTOCOLNO>'.$fdata['protocolno'].'</PROTOCOLNO>'.
        '<SIGN>'.md5($sign).'</SIGN>'.
        '</REQUEST>';
        $des=Crypt3Des::encrypt_base64($xml,$this->fkey);
        // $url='http://www-1.fuioupay.com:18670/mobile_pay/newpropay/unbind.pay';
        $url='https://mpay.fuioupay.com/newpropay/unbind.pay';
        $datas['MCHNTCD']=$this->mchntcd;
        $datas['APIFMS']=$des;
        $res=Curl::http_curl($url,$datas);
        $ddes=Crypt3Des::decrypt_base64($res,$this->fkey);
        $vres=simplexml_load_string($ddes);//返回里的协议号 PROTOCOLNO 有什么作用
        if ($vres->RESPONSECODE==0000) {
            return json(['code' => 200, 'msg' =>$vres->RESPONSEMSG]);exit();
        }else{
            return json(['code' => $vres->RESPONSECODE, 'msg' =>$vres->RESPONSEMSG]);exit();
        }

    }
    //协议卡查询
    public function bank_authqb(){
        $fdata['version']="1.0";
        $fdata['mchntcd']=$this->mchntcd;
        $fdata['userid']=20; 
        $sign=$fdata['version'].'|'.$fdata['mchntcd'].'|'.$fdata['userid'].'|'.$this->fkey;
        $xml='<?xml version="1.0" encoding="UTF-8" standalone="no"?>'.
        '<REQUEST>'.
        '<VERSION>1.0</VERSION>'.
        '<MCHNTCD>'.$fdata['mchntcd'].'</MCHNTCD>'.
        '<USERID>'.$fdata['userid'].'</USERID>'.
        '<SIGN>'.md5($sign).'</SIGN>'.
        '</REQUEST>';
        $des=Crypt3Des::encrypt_base64($xml,$this->fkey);
        $url='https://mpay.fuioupay.com/newpropay/bindQuery.pay';
        $datas['MCHNTCD']=$this->mchntcd;
        $datas['APIFMS']=$des;
        $res=Curl::http_curl($url,$datas);
        $ddes=Crypt3Des::decrypt_base64($res,$this->fkey);
        $vres=simplexml_load_string($ddes);//返回里的协议号 PROTOCOLNO 有什么作用
        if ($vres->RESPONSECODE==0000) {
            return json(['code' => 200, 'msg' =>$vres->PROTOCOLNO]);exit();//结果:YQ6D5I100045050001L7GR
        }else{
            return json(['code' => $vres->RESPONSECODE, 'msg' =>$vres->RESPONSEMSG]);exit();
        }

    }
    //银行卡认证结果
    public function get_bank_auth(){
        if(!empty(input("param.token"))){
            $token=input("param.token");
        }else{
            return json(['code' => 501, 'msg' => '令牌呢？']);exit();
        }
        $id=$this->do_mdecrypt($token);
        $res=Db::name('users')->alias('a')->join('bank b', 'a.bank_cdid = b.id','LEFT')->field('a.bank_name,a.bank_number,b.bank')->where(array('id'=>$id))->find();
        if(!empty($res['bank_number'])){
            $star=substr($res['bank_number'],6,10);
            $res['bank_number']=str_replace($star,'**** **** **',$res['bank_number']);
            return json(['code' => 200, 'msg' => '查询成功' ,'data' =>$res]);exit();
            
        }else{
            return json(['code' => 500, 'msg' => '查询失败']);exit();
        }
    }
    //商家给客户借款
    public function bank_moneyout(){
        $data['ver']="1.0";
        $data['merdt']="20190201";
        $data['orderno']="20190201143624153"; //订单表order_no字段，必须是数字字符串
        $data['bankno']="0102"; //总行代码
        $data['cityno']="";//城市代码
        $data['branchnm']="";//支行代码
        $data['accntno']="6212264000061322570";
        $data['accntnm']="唐美冬";
        $data['amt']="100";//单位：分，最少3元
        $data['entseq']="test";//企业流水号
        $data['memo']="贷款";
        $data['mobile']="13667211357";
        $data['addDesc']="1";//是否返回交易状态
        $xml='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.
        '<payforreq>'.
        '<ver>1.0</ver>'.
        '<merdt>20190201</merdt>'.
        '<orderno>20190201143624153</orderno>'.
        '<bankno></bankno>'.
        '<cityno></cityno>'.
        '<branchnm></branchnm>'.
        '<accntno>6222023803013297860</accntno>'.
        '<accntnm>宋承宪</accntnm>'.
        '<amt>10</amt>'.
        '<entseq></entseq>'.
        '<memo></memo>'.
        '<mobile>13667211357</mobile>'.
        '<addDesc>1</addDesc>'.
        '</payforreq>';
        $mchntcd="0002900F0345178";
        $mchntkey="123456";
        $reqtype="payforreq";
        $macsource=$mchntcd."|".$mchntkey."|".$reqtype."|".$xml;
        $mac=md5($macsource);
        $mac=strtoupper($mac);
        $list=array("merid"=>$mchntcd,"reqtype"=>$reqtype,"xml"=>$xml,"mac"=>$mac);
        // $url="https://fht-api.fuioupay.com/req.do";//正式
        $url="https://fht-test.fuioupay.com/fuMer/req.do";//测试
        $result=Curl::https_curl($url,$list);
        return json(['code' => 200, 'msg' =>$result]);exit();
    }
    //用户还款给商户
    public function bank_moneyin(){
        $orderinfos=Db::name('orders')->where(['state'=>[17,19]])->where('hktime','<',time())->select();
        for ($i=0; $i <count($orderinfos) ; $i++) {
            $orderinfode=Db::name('orderdetail')->where('order_id',$orderinfos[$i]['id'])->where('state',1)->order('id asc')->find();
            if($orderinfode){
                $orindetail=Db::name('orderdetail')->alias('a')->join('orders b', 'a.order_id = b.id','LEFT')->join('users c', 'b.user_id = c.id','LEFT')->field('a.*,c.id as userId,c.phone,c.protocolno')->where('a.id',$orderinfode['id'])->find();
                $fdata['version']="1.0";
                $fdata['userip']="116.239.4.194";
                $fdata['mchntcd']=$this->mchntcd;
                $fdata['type']="03";
                $fdata['mchntorderid']=date('YmdHis').mt_rand(1000,9999);//流水号  
                $fdata['userid']=$orindetail['userId']; 
                $fdata['amt']=$orderinfode['money']*100;
                $fdata['protocolno']=$orindetail['protocolno']; 
                $fdata['needsendmsg']="0"; 
                $fdata['backurl']="http://www.kbb123.com/api/bank/test_backurl";
                $fdata['rem1']="";
                $fdata['rem2']="";
                $fdata['rem3']="";
                $fdata['signtp']="md5";
                $sign=$fdata['type'].'|'.$fdata['version'].'|'.$fdata['mchntcd'].'|'.$fdata['mchntorderid'].'|'.$fdata['userid'].'|'.$fdata['protocolno'].'|'.$fdata['amt'].'|'.$fdata['backurl'].'|'.$fdata['userip'].'|'.$this->fkey;
                $xml='<?xml version="1.0" encoding="UTF-8" standalone="no"?>'.
                '<REQUEST>'.
                '<VERSION>1.0</VERSION>'.
                '<USERIP>'.$fdata['userip'].'</USERIP>'.
                '<MCHNTCD>'.$fdata['mchntcd'].'</MCHNTCD>'.
                '<TYPE>03</TYPE>'.
                '<MCHNTORDERID>'.$fdata['mchntorderid'].'</MCHNTORDERID>'.
                '<USERID>'.$fdata['userid'].'</USERID>'.
                '<AMT>'.$fdata['amt'].'</AMT>'.
                '<PROTOCOLNO>'.$fdata['protocolno'].'</PROTOCOLNO>'.
                '<NEEDSENDMSG>0</NEEDSENDMSG>'.
                '<BACKURL>'.$fdata['backurl'].'</BACKURL>'.
                '<REM1></REM1>'.
                '<REM2></REM2>'.
                '<REM3></REM3>'.
                '<SIGNTP>MD5</SIGNTP>'.
                '<SIGN>'.md5($sign).'</SIGN>'.
                '</REQUEST>';
                $des=Crypt3Des::encrypt_base64($xml,$this->fkey);
                $url='http://www-1.fuioupay.com:18670/mobile_pay/newpropay/order.pay';//测试
                // $url='https://mpay.fuioupay.com/newpropay/order.pay';
                $datas['MCHNTCD']=$this->mchntcd;
                $datas['APIFMS']=$des;
                $res=Curl::http_curl($url,$datas);
                $ddes=Crypt3Des::decrypt_base64($res,$this->fkey);
                $vres=simplexml_load_string($ddes);//返回里的协议号 PROTOCOLNO 有什么作用
                Db::name('test')->where('id',2)->update(['test'=>123]);
                Db::name('test')->where('id',3)->update(['test'=>$vres]);
                if ($vres->RESPONSECODE==0000) {
                    Db::name('orderdetail')->where('id',$orderinfode['id'])->update(['state'=>2,'order_nod'=>$vres->MCHNTORDERID,'order_fy'=>$vres->ORDERID]);
                    $exordetail=Db::name('orderdetail')->where('order_id',$orderinfos[$i]['id'])->where('state',1)->find();
                    if($exordetail){
                        Db::name('orders')->where('id',$orderinfos[$i]['id'])->update(['hktime'=>time()+86400*7]);
                    }else{
                        Db::name('orders')->where('id',$orderinfos[$i]['id'])->update(['state'=>21]);
                    }
                }else{
                    Db::name('orderdetail')->where('id',$orderinfode['id'])->update(['order_nod'=>'失败']);
                }
            }else{
                Db::name('orders')->where('id',$orderinfos[$i]['id'])->update(['state'=>21]);
            }
        }
        return json(['code' => 200, 'msg' =>'ok!']);exit();
    }
    public function testsms(){
        $abc='qkpKyYyHiphK5QsmwdqcVhE8CxNl+BDTFCo2F7fV5H3kea4al1Es9QLiLileOa5SCMX0SVDjbl9rPALV046yB7ihqpX8t/EZiAZhOSqW1vojy3F7g/ir0c40O08M3iuSU9p/ZLjceFmwCYKCK/QWHifcRasHANYPXVlBGPaDCCrSJbX+WQUmK3xEf2gdUSMQ1h+s0Y3XwxBljClUeEyZcXxEf2gdUSMQ42crjc06JR/8W0Ds26bh+6tclFOuMXMMRejCwy7j0lHOhfTgFLbMQxaV00x8J8ixDsFnRZHdqkLksZ2WUHcjbubifJvEf/LampXOZwWw/9fdod1uPR3mGvEDtex+CTyohDiJO0dUc+Y=';
        $ddes=Crypt3Des::decrypt_base64($abc,'5old71wihg2tqjug9kkpxnhx9hiujoqj');
        $vres=simplexml_load_string($ddes);
        if ($vres->RESPONSECODE==0000) {
            return json(['code' => 200, 'msg' =>$vres->RESPONSEMSG]);exit();
        }else{
            return json(['code' => $vres->RESPONSECODE, 'msg' =>$vres->RESPONSEMSG]);exit();
        }
    }
    public function testvb(){
        $abc='qkpKyYyHiphK5QsmwdqcVhE8CxNl+BDTFCo2F7fV5H3kea4al1Es9QLiLileOa5SCMX0SVDjbl9rPALV046yB7ihqpX8t/EZiAZhOSqW1vojy3F7g/ir0c40O08M3iuSrfSrAlWy3D2wCYKCK/QWHifcRasHANYPXVlBGPaDCCoINvgFTmDEtyAIEdx2S9ZUXBvhzm/F+8b6T3rTCXgHzdx833uPmkZ4/G7xenhNkT/qc7CGaMc8ozq03jdoc5cRXq4p16gm16C7skl76vZ6mfIhoMIwO4f63N7qsL0UE24Jf7bUVcUyTRhWDqPH8Ul4wmXE/jehRto=';
        $ddes=Crypt3Des::decrypt_base64($abc,'5old71wihg2tqjug9kkpxnhx9hiujoqj');
        $vres=simplexml_load_string($ddes);
        if ($vres->RESPONSECODE==0000) {
            return json(['code' => 200, 'msg' =>$vres->RESPONSEMSG]);exit();
        }else{
            return json(['code' => $vres->RESPONSECODE, 'msg' =>$vres->RESPONSEMSG]);exit();
        }
    }
    public function testmoneyin(){
        $abc='qkpKyYyHiphK5QsmwdqcVhE8CxNl+BDTFCo2F7fV5H3kea4al1Es9QLiLileOa5SCMX0SVDjbl9rPALV046yB7ihqpX8t/EZiAZhOSqW1vojy3F7g/ir0c40O08M3iuSteJ4/N1t+SCwCYKCK/QWHifcRasHANYPXVlBGPaDCCoB3Ew921GbolE+QzSRge5CokKSdSqf7EJdWUEY9oMIKlYLtu7t2edcEG4TVuS+Y7LhM1sMQ7O0U+7w46ZFKsWapYdzdPKAbYZ18ms1aUc/THjjjWkEoOnBS1Tbf9ux+8aAaFhwvTrRnIkAPU0hvuw1SwRmLE0oZSJDSatqZTCOe1zpqyyC03g22FYvQ8jSvyxhfL3tUYbiH2lsrbJGACw5ozA51HpBmPlThMhfvrMH8r4hdz10PULQdvjx5utxBuM66LRTkGZ+mCYMqjOMyUBItItifKTqZ725JRk85vlV6UzcbVXMEU/+yLtbBkGHFQZZYue4ZkDR3YHYW43PYPoy2psPHW9Wv2OcxMO+M+YjnF8eNJPbTpC0mEYT56OR2mMbczYmPnVpVvO9EMvAfZQXwmXE/jehRto=';
        $ddes=Crypt3Des::decrypt_base64($abc,'5old71wihg2tqjug9kkpxnhx9hiujoqj');
        $vres=simplexml_load_string($ddes);
        if ($vres->RESPONSECODE==0000) {
            return json(['code' => 200, 'msg' =>$vres->RESPONSEMSG]);exit();
        }else{
            return json(['code' => $vres->RESPONSECODE, 'msg' =>$vres->RESPONSEMSG]);exit();
        }
    }
    public function test_backurl(){
        $rel1=file_get_contents('php://input');
        // $data=json_decode($rel1);
        Db::name('test')->where('id',1)->update(['test'=>$rel1]);
    }
    public function test(){
        $test=Db::name('test')->where('id',1)->find();
        $tmd=json_encode($test['test'],true);
        return $test['test'];
    }
	//绑定银行卡
	public function bank_regist(){
        if(!empty(input("param.token"))){
            $token=input("param.token");
        }else{
            return json(['code' => 501, 'msg' => '令牌呢？']);exit();
        }
        if(!empty(input("param.bank_name"))){
            $data['bank_name']=input("param.bank_name");
        }else{
            return json(['code' => 502, 'msg' => '姓名不能为空']);exit();
        }
        if(!empty(input("param.bank_idcard"))){
            $data['bank_idcard']=input("param.bank_idcard");
        }else{
            return json(['code' => 503, 'msg' => '身份证号不能为空']);exit();
        }
        if(!empty(input("param.bank_number"))){
            $data['bank_number']=input("param.bank_number");
        }else{
            return json(['code' => 504, 'msg' => '银行卡号不能为空']);exit();
        }
        if(!empty(input("param.bank_phone"))){
            $data['bank_phone']=input("param.bank_phone");
        }else{
            return json(['code' => 505, 'msg' => '银行预留手机号不能为空']);exit();
        }
        $data['bank_id']=input("param.bank_id");
        $id=$this->do_mdecrypt($token);
        $res=Db::name('users')->where(array('id'=>$id))->update($data);
        if($res){
            return json(['code' => 200, 'msg' => '绑定成功' ,'data' =>$res]);exit();
        }else{
            return json(['code' => 500, 'msg' => '绑定失败']);exit();
        }
	}
    //解密
    private function do_mdecrypt($string, $key=''){
        $key= !empty($key) ? $key : config('byzk.KEY');
        $operation = 'D';
        $key=md5($key); 
        $key_length=strlen($key); 
        $string=$operation=='D'?base64_decode($string):substr(md5($string.$key),0,8).$string; 
        $string_length=strlen($string); 
        $rndkey=$box=array(); 
        $result=''; 
        for($i=0;$i<=255;$i++){ 
            $rndkey[$i]=ord($key[$i%$key_length]); 
            $box[$i]=$i; 
        } 
        for($j=$i=0;$i<256;$i++){ 
            $j=($j+$box[$i]+$rndkey[$i])%256; 
            $tmp=$box[$i]; 
            $box[$i]=$box[$j]; 
            $box[$j]=$tmp; 
        } 
        for($a=$j=$i=0;$i<$string_length;$i++){ 
            $a=($a+1)%256; 
            $j=($j+$box[$a])%256; 
            $tmp=$box[$a]; 
            $box[$a]=$box[$j]; 
            $box[$j]=$tmp; 
            $result.=chr(ord($string[$i])^($box[($box[$a]+$box[$j])%256])); 
        } 
        if($operation=='D'){ 
            if(substr($result,0,8)==substr(md5(substr($result,8).$key),0,8)){ 
                return substr($result,8); 
            }else{ 
                return''; 
            } 
        }else{ 
            return str_replace('=','',base64_encode($result)); 
        } 
    }
}